package main

import (
	"context"
	"fmt"
	logging "github.com/sirupsen/logrus"
	"google.golang.org/grpc"
	"webdemo/src/grpc/helper"
	"webdemo/src/grpc/service"
)

func main() {
	/*certFile, err := credentials.NewClientTLSFromFile("src/grpc-client/keys/server.crt", "zhengwei")
	if err != nil {
		logging.Error("credentials.NewServerTLSFromFile error is ", err)
		return
	}*/
	certs := helper.GetClientCerts()

	// 使用证书
	//conn, err := grpc.Dial(":8081",grpc.WithInsecure())
	conn, err := grpc.Dial(":8081", grpc.WithTransportCredentials(certs))

	if err != nil {
		logging.Error("grpc.Dial", err)
		return
	}
	defer conn.Close()
	client := service.NewProductServiceClient(conn)
	product, err := client.GetProduct(context.Background(), &service.ProductRequest{
		ProductId: 1,
	})
	if err != nil {
		logging.Error("client.GetProduct", err)
		return
	}
	fmt.Println(product)

}
